package com.edu.medicalpro.RecyclerViewadapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.edu.medicalpro.R;
import com.edu.medicalpro.activity.DateActivity;
import com.edu.medicalpro.bean.HaeFeiBean;

import java.util.ArrayList;
import java.util.List;

public class HuaFeiAdapter extends RecyclerView.Adapter<HuaFeiAdapter.MyHolder> {

    private Context context;
    private List<HaeFeiBean> dataList;

    public HuaFeiAdapter() {
        dataList = new ArrayList<>();
        HaeFeiBean haeFeiBean=new HaeFeiBean();
        haeFeiBean.setStartDate("2023-4-21");
     //   haeFeiBean.setEndDate("2023-4-29");
     //   Log.e("111",haeFeiBean.getEndDate()) ;
    }

    public void setDataList(List<HaeFeiBean> dataList) {
        this.dataList = dataList;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        MyHolder holder =new MyHolder(LayoutInflater.from(context).inflate(R.layout.huafei_adapter_item,null));
        return holder;
    }

    @Override
    public void onBindViewHolder( MyHolder holder, int position) {
        holder.startDate.setText(dataList.get(position).getStartDate());
        holder.endDate.setText(dataList.get(position).getEndDate());
        holder.startDate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
    }

    @Override
    public int getItemCount() {
        return null==dataList ? 0:dataList.size();
    }

    class MyHolder extends RecyclerView.ViewHolder{
        TextView startDate;
        TextView endDate;

        public MyHolder( View itemView) {
            super(itemView);
            startDate=itemView.findViewById(R.id.jiancha_Data_text1);
            endDate=itemView.findViewById(R.id.jiancha_Data_text2);

            startDate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (itemListener!=null){
                        itemListener.StartOnItemClick(getAdapterPosition());
                    }
                }
            });
            endDate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (itemListener!=null){
                        itemListener.EndOnItemClick(getAdapterPosition());
                    }
                }
            });
        }
    }
    private static OnClickRecycleItemListener  itemListener;

    public void setOnClickRecycleItemListener(OnClickRecycleItemListener itemListener) {
        this.itemListener = itemListener;
    }


    //条目点击  接口
    public interface OnClickRecycleItemListener{
        void StartOnItemClick(int position);
        void EndOnItemClick(int position);
    }

}
